package com.ls.fw.data.hbase.support.uniquekey;

import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Hex;

public class HexUniqueKeyFormatter extends BaseUniqueKeyFormatter implements UniqueKeyFormatter {

    @Override
	public String encodeAsString(byte[] bytes) {
        return Hex.encodeHexString(bytes);
    }

    @Override
	public byte[] decodeFromString(String value) {
        try {
            return Hex.decodeHex(value.toCharArray());
        } catch (DecoderException e) {
            throw new IllegalArgumentException("Value '" + value + "' can't be decoded as hex", e);
        }
    }
}
